package com.music.mysongs.helper

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences

fun SharedPreferences.myClear() {//mClear: SharedPreferences.Editor.() -> Unit
    val editor = edit()
    editor.clear()
    editor.apply()
}

fun myActReadStringSPF(act: Activity?, mKey: String): String? {
    val mySPf = act?.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)
    return mySPf?.getString(mKey, "none")
}

fun myActReadIntSPF(act: Activity?, mKey: String): Int? {
    val mySPf = act?.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)
    return mySPf?.getInt(mKey, -1)
}

fun myActWriteSPF(act: Activity?, mKey: String, stringV: String?, intV: Int?) {
    val editor = act?.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)?.edit()
    if (intV != null) {
        editor?.putInt(mKey, intV)
    } else {
        editor?.putString(mKey, stringV)
    }
    editor?.apply()
}

fun myCxtReadStringSPF(cxt: Context, mKey: String): String? {
    val mySPF = cxt.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)
    return mySPF?.getString(mKey, "none")
}

fun myCxtReadIntSPF(cxt: Context, mKey: String): Int? {
    val mySPF = cxt.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)
    return mySPF?.getInt(mKey, -1)
}

fun myCxtWriteSPF(cxt: Context, mKey: String, stringV: String?, intV: Int?) {
    val editor = cxt.getSharedPreferences("DataSPF", Context.MODE_PRIVATE)?.edit()
    if (intV != null) {
        editor?.putInt(mKey, intV)
    } else {
        editor?.putString(mKey, stringV)
    }
    editor?.apply()
}